package com.example.cookie02.conterller;

import com.alibaba.fastjson.JSON;
import com.example.cookie02.dao.PersonDao;
import com.example.cookie02.dao.imp.PersonDaoImpl;
import com.example.utrl.PageUntil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.Map;

/**
 * @author ：lqs
 * @date ：Created in 2023/8/30 12:08
 * @description：
 * @modified By：
 * @version:
 */
@WebServlet("/show")
public class Showconterller extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        PersonDaoImpl personDao = new PersonDaoImpl();
        PageUntil pageUntil = new PageUntil();
        int pageIndex=1;


//初始化PageUntil
        if(req.getParameter("pageIndex")!=null){
            //获取pageIndex的值
            pageIndex = Integer.valueOf(req.getParameter("pageIndex"));

        }

        if(req.getParameter("getname")!=null){
            String getname = req.getParameter("getname");
            List<Map<String,Object>> mapList=personDao.queryName(getname);

        }


        //设置每页个数
        pageUntil.setPageSize(5);
        int PageSize = pageUntil.getPageSize();
        //设置总页数
        pageUntil.setPageTotalCount(personDao.AllCount());
        //设置当前页数
        pageUntil.setPageIndex(pageIndex);
        //
        List<Map<String,Object>> list = personDao.queryOnePage(pageIndex,PageSize);
        req.setAttribute("show",list);
        req.setAttribute("pageUntil",pageUntil);
        req.getRequestDispatcher("/show.jsp").forward(req, resp);
    }
}

